home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoCommandHistory.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.2 KB  |  199 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2000 Werner Trobin <trobin@kde.org>
  3.    Copyright (C) 2000 David Faure <faure@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef kocommandhistory_h
  22. #define kocommandhistory_h
  23.  
  24. #include <qptrlist.h>
  25. #include <qstring.h>
  26. #include <qobject.h>
  27. #include <koffice_export.h>
  28.  
  29. class KAction;
  30. class KActionCollection;
  31. class QPopupMenu;
  32. class KCommand;
  33. #include <qlistbox.h>
  34.  
  35. class KoListBox : public QListBox {
  36.     Q_OBJECT
  37. public:
  38.     KoListBox( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
  39. protected:
  40.     virtual void contentsMouseMoveEvent ( QMouseEvent * );
  41.     virtual QSize sizeHint() const;
  42. signals:
  43.     void changeNumberOfSelectedItem( int );
  44. };
  45.  
  46. /**
  47.  * The command history stores a (user) configurable amount of
  48.  * Commands. It keeps track of its size and deletes commands
  49.  * if it gets too large. The user can set a maximum undo and
  50.  * a maximum redo limit (e.g. max. 50 undo / 30 redo commands).
  51.  * The KoCommandHistory keeps track of the "borders" and deletes
  52.  * commands, if appropriate. It also activates/deactivates the
  53.  * undo/redo actions in the menu and changes the text according
  54.  * to the name of the command.
  55.  *
  56.  * @short History of user commands (for undo/redo)
  57.  */
  58. class KOFFICEUI_EXPORT KoCommandHistory : public QObject {
  59.     Q_OBJECT
  60. public:
  61.     /**
  62.      * Creates a command history, to store commands.
  63.      * This constructor doesn't create actions, so you need to call
  64.      * #undo and #redo yourself.
  65.      */
  66.     KoCommandHistory();
  67.  
  68.     /**
  69.      * Creates a command history, to store commands.
  70.      * This also creates an undo and a redo action, in the @p actionCollection,
  71.      * using the standard names ("edit_undo" and "edit_redo").
  72.      *
  73.      * @param actionCollection the collection to put the history in.
  74.      * @param withMenus if true, the actions will display a menu when plugged
  75.      * into a toolbar.
  76.      */
  77.     KoCommandHistory(KActionCollection *actionCollection, bool withMenus = true);
  78.  
  79.     /**
  80.      * Destructs the command history object.
  81.      */
  82.     virtual ~KoCommandHistory();
  83.  
  84.     /**
  85.      * Erases all the undo/redo history.
  86.      * Use this when reloading the data, for instance, since this invalidates
  87.      * all the commands.
  88.      */
  89.     void clear();
  90.  
  91.     /**
  92.      * Adds a command to the history. Call this for each @p command you create.
  93.      * Unless you set @p execute to false, this will also execute the command.
  94.      * This means, most of the application's code will look like:
  95.      *
  96.      *    MyCommand * cmd = new MyCommand(i18n("The Name"), parameters);
  97.      *    m_historyCommand.addCommand( cmd );
  98.      */
  99.     void addCommand(KCommand *command, bool execute=true);
  100.  
  101.     /**
  102.      * @return the maximum number of items in the undo history
  103.      */
  104.     int undoLimit() const { return m_undoLimit; }
  105.     /**
  106.      * Sets the maximum number of items in the undo history.
  107.      */
  108.     void setUndoLimit(int limit);
  109.     /**
  110.      * @return the maximum number of items in the redo history
  111.      */
  112.     int redoLimit() const { return m_redoLimit; }
  113.     /**
  114.      * Sets the maximum number of items in the redo history.
  115.      */
  116.     void setRedoLimit(int limit);
  117.  
  118.     /**
  119.      * Enable or disable the undo and redo actions.
  120.      * This isn't usually necessary, but this method can be useful if
  121.      * you disable all actions (to go to a "readonly" state), and then
  122.      * want to come back to a readwrite mode.
  123.      */
  124.     void updateActions();
  125.  
  126.     /**
  127.      * @return the current top item on the history stack
  128.      */
  129.     KCommand * presentCommand();
  130.  
  131. public slots:
  132.     /**
  133.      * Undoes the last action.
  134.      * Call this if you don't use the builtin KActions.
  135.      */
  136.     virtual void undo();
  137.     /**
  138.      * Redoes the last undone action.
  139.      * Call this if you don't use the builtin KActions.
  140.      */
  141.     virtual void redo();
  142.     /**
  143.      * Remembers when you saved the document.
  144.      * Call this right after saving the document. As soon as
  145.      * the history reaches the current index again (via some
  146.      * undo/redo operations) it will emit @ref documentRestored
  147.      * If you implemented undo/redo properly the document is
  148.      * the same you saved before.
  149.      */
  150.     virtual void documentSaved();
  151.  
  152. protected slots:
  153.     void slotUndoAboutToShow();
  154.     void slotUndoActivated( int );
  155.     void slotRedoAboutToShow();
  156.     void slotRedoActivated( int );
  157.     void slotUndoActivated( QListBoxItem *);
  158.     void slotRedoActivated( QListBoxItem *);
  159.     void slotChangeRedoNumberOfSelectedItem( int );
  160.     void slotChangeUndoNumberOfSelectedItem( int );
  161. signals:
  162.     /**
  163.      * Emitted every time a command is executed
  164.      * (whether by addCommand, undo or redo).
  165.      * You can use this to update the GUI, for instance.
  166.      */
  167.     void commandExecuted();
  168.  
  169.     /**
  170.      * Emitted every time a command is executed
  171.      * (whether by addCommand, undo or redo).
  172.      * You can use this to update the GUI, for instance.
  173.      * @param command was executed
  174.      */
  175.     void commandExecuted(KCommand *cmd);
  176.  
  177.     /**
  178.      * Emitted every time we reach the index where you
  179.      * saved the document for the last time. See @ref #documentSaved
  180.      */
  181.     void documentRestored();
  182.  
  183. private:
  184.     void clipCommands();  // ensures that the limits are kept
  185.  
  186.     QPtrList<KCommand> m_commands;
  187.     KAction *m_undo, *m_redo;
  188.     QPopupMenu *m_undoPopup, *m_redoPopup;
  189.     int m_undoLimit, m_redoLimit;
  190.     bool m_first;  // attention: it's the first command in the list!
  191. protected:
  192.     virtual void virtual_hook( int id, void* data );
  193. private:
  194.     class KoCommandHistoryPrivate;
  195.     KoCommandHistoryPrivate *d;
  196. };
  197.  
  198. #endif
  199.